//
//  MyViewController.m
//  Civacrm
//
//  Created by 王桂敏 on 2017/2/4.
//  Copyright © 2017年 王桂敏. All rights reserved.
//

#import "MyViewController.h"
#import "MyTableViewCell.h"
#import "MyAccountViewController.h"
#import "SettingViewController.h"
#import "MyStudyViewController.h"

static NSString * MyTableViewCellReuseID = @"MyTableViewCell";


@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic , strong) UITableView * myTableView;
@property (nonatomic , strong) NSArray * textArray;
@property (nonatomic , strong) NSArray * imageArray;

@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initNavigation];
    [self initData];
    [self initView];
}

-(void)initData
{
    self.textArray = [NSArray arrayWithObjects:@"我的账号",@"设置", nil];
    self.imageArray = [NSArray arrayWithObjects:@"btn_woa",@"btn_set", nil];
}

- (void)initView
{
    self.myTableView = [[UITableView alloc]initWithFrame:self.view.frame style:(UITableViewStyleGrouped)];
    [self.myTableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:MyTableViewCellReuseID];
    [self.view addSubview:self.myTableView];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.rowHeight = 50;
    self.myTableView.backgroundColor = GlobalBgColor;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.textArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:MyTableViewCellReuseID forIndexPath:indexPath];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.leftImageView.image = Image(self.imageArray[indexPath.section]);
    cell.contentLabel.text = self.textArray[indexPath.section];
    
    if (indexPath.section == 0) {
        
        cell.userNameLabel.text = self.nickName;
        
    }else
    {
        cell.userNameLabel.hidden = YES;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0) {
       
        [self toMyAccount];
        
    }else
    {
        [self toSetting];
    }
}

- (void)toMyAccount
{
    MyAccountViewController * myAccountVC = [[MyAccountViewController alloc]init];
    [self.navigationController pushViewController:myAccountVC animated:YES];
}

- (void)toMyStudy
{
    MyStudyViewController * myStudy = [[MyStudyViewController alloc]init];
    [self.navigationController pushViewController:myStudy animated:YES];
}

- (void)toSetting
{
    SettingViewController * settingVC = [[SettingViewController alloc]init];
    [self.navigationController pushViewController:settingVC animated:YES];
}

- (void)initNavigation
{
    self.title = @"个人中心";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
